/**
 * Created by sxx on 2017/5/1.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/jquery.validate.min.js";
import productEditTpl from './product_edit.handlebars';
import httpurl from "../../../unit/common/js/httpurl";

let token = sessionStorage.getItem('supplier_token');

let prodId = httpurl.uri.params.id;
let ProductDetail = {
    init: function(){
        this.getInfo()
            .then(this.renderList)
            .then(this.bindEvent);
    },
    getInfo: function(){
        return new Promise((resolve, reject)=>{
            $.ajax({
                url: HOST_ADDR+'/cpmp/splrSlfMng/selfProd/'+prodId,
                type: 'get',
                dataType: 'json',
                headers: {
                    'access_token': token,
                    'login_type': 'splr'
                },
                contentType:"application/json",
                success: function(rsp){
                    console.log(rsp);
                    resolve(rsp);
                }
            })
        });
    },
    renderList: function(rsp){
        let productHtml = productEditTpl(rsp.data);
        $('.J_edit-product-form').html(productHtml);
    },
    bindEvent: function(){
        $('.J_back-to-list').unbind().click(function(){
            location.href = '/supplier_self/product_list.html';
        });
    }

}
ProductDetail.init();


